package com.liangchen.asperf;

import android.content.Context;
import android.os.Looper;
import android.util.Log;
import android.util.Printer;

public class AsPerfManager {
    private final String TAG = "AsPerfManager";
    private static Context mContext;

    private boolean mTurnOnFps = true;
    private boolean mTurnOnJank = true;
    private static FpsTracker sFpsTracker;

    private AsPerfManager() {
    }

    public static class InnerHolder {
        public static final AsPerfManager instance = new AsPerfManager();

    }

    public static AsPerfManager getInstance() {
        return AsPerfManager.InnerHolder.instance;
    }

    public void init(Context context) {
        mContext = context;
        if (mTurnOnFps) {
            monitorUIFps();
        }
        if (mTurnOnJank) {
            monitorMainThreadJank();
        }
    }

    private void monitorUIFps() {
        Log.i("cdgtest", "start monitor ui fps");
        if (sFpsTracker == null){
            sFpsTracker = new FpsTracker();
        }
        sFpsTracker.start();
    }

    public FpsTracker getFpsTracer(){
        if (sFpsTracker == null){
            sFpsTracker =new FpsTracker();
        }
        return sFpsTracker;
    }

    private void monitorMainThreadJank() {
        Printer printer = new Printer() {
            @Override
            public void println(String x) {

            }
        };

        Looper.getMainLooper().setMessageLogging(printer);

    }

    public class LogPrinter implements Printer {

        @Override
        public void println(String x) {

        }
    }

}
